/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aljfce.business.event.boundary;

import com.aljfce.business.entity.Event;
import com.aljfce.business.entity.User;
import java.io.Serializable;
import java.security.Principal;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Jacopo Ferrigno <jacopo.ferrigno@gmail.com>
 */
@ManagedBean
@ViewScoped
public class EventDetailBean implements Serializable{
    public static String IN_CALENDAR_EVENT = "in_calendar";
    public static String OWN_EVENT = "own_event";
    public static String INVITED_EVENT = "invited";
    
    @Inject 
    private User user;
    
    @PersistenceContext
    EntityManager em;
    
    @PostConstruct
    public void init(){
        FacesContext contex = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) contex.getExternalContext().getRequest();
        Principal principal = request.getUserPrincipal();
        //This should not appen but just in case
        if(principal == null ){
            this.user = null;
            return;
        }
        
        this.user = em.find(User.class, principal.getName());
    }

    public String getIN_CALENDAR_EVENT() {
        return IN_CALENDAR_EVENT;
    }

    public String getOWN_EVENT() {
        return OWN_EVENT;
    }

    public String getINVITED_EVENT() {
        return INVITED_EVENT;
    }
    
    public String getEventType(Event event){
        //TODO write real implementaiton
        
        return "";
    }
            
    
    
    
    
}
